using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

using usm.SolDev.Common.Constants;

namespace usm.SolDev.UI
{
    public partial class BaseForm : Form
    {

        #region Common utilities functions
        public static new bool DesignMode
        {
            get
            {
                return (Process.GetCurrentProcess ().ProcessName.Equals ("devenv"));
            }
        }

        /// <summary>
        ///     Call this member function to hide base panel and to show waiting 
        /// image and operation cancel button. Used when a long run operation is 
        /// started.
        /// </summary>
        public void StartWaiting ()
        {
            pnlBasePanel.Visible = false;

            btnOperationCancel.Visible = true;
            btnOperationCancel.Enabled = true;
            pbWaitImage.Visible = true;
        }

        /// <summary>
        ///     Call this member function to show base panel and to hide waiting 
        /// image and operation cancel button. Used when a long run operation is 
        /// finished.
        /// </summary>
        public void EndWaiting()
        {
            btnOperationCancel.Visible = false;
            btnOperationCancel.Enabled = false;
            pbWaitImage.Visible = false;

            pnlBasePanel.Visible = true;
        }

        #endregion
        /// <summary>
        ///     Default constructor
        /// </summary>
        public BaseForm ()
        {
            InitializeComponent ();
        }

        /// <summary>
        ///     Catch on resize event and resize image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BaseForm_Resize(object sender, EventArgs e)
        {
            pbWaitImage.Left = (int)(Width / 2 - pbWaitImage.Width / 2);
            pbWaitImage.Top = (int)(Height / 2 - pbWaitImage.Height / 2);

            btnOperationCancel.Left = (int)(Width / 2 - btnOperationCancel.Width / 2);
            btnOperationCancel.Top = pbWaitImage.Top + pbWaitImage.Height + 5;
        }

        /// <summary>
        ///     On cancel operation, close the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOperationCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        ///     Close event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void FormClosedEvent(object sender, FormClosedEventArgs e)
        {
        }
    }
}